export default class extends Map {
    constructor(obj, isExtends){
        super()
        this.type      = obj.type || 1;
        this.source    = obj.source || 'BeiJing-FRONT-TEST-OVL';
        this.qos       = obj.qos || 0;
        this.status    = 's1';//send accept confirm
        this.subscribe = obj.subscribe || null; //房间号
        this.error     = obj.error || 0;
        this.data      = Object.assign(isExtends ? {
            content: '',
            ct     : 98,
            did    : '',
            icon   : '',
            ip     : '0.0.0.0',
            nick   : '游客',
            pg     : 98,
            rg     : 98,
            ts     : new Date().getTime(),
            uid    : 0,
            sts    : 0,
            type   : 0,
            room   : ''
        } : {}, obj.data);
        this.send      = 1;
        this.event     = 'message'; //receive reply 
        this.from      = 'server';
        this.id        =  this.subscribe +'@'+ new Date().getTime() +'@'+ (Math.random() * 0x1000000 << 0).toString(16) +'@'+ this.from;
        
        if(isExtends){
            Object.assign(this, obj);
        }
        
    }

    getObject(){
        return {
            type     : this.type,
            qos      : this.qos,
            source   : this.source,
            status   : this.status,
            subscribe: this.subscribe,
            data     : this.data,
            send     : this.send,
            event    : this.event,
            from     : this.from,
            error    : this.error,
            id       : this.id
        }
    }

    getRoomId(){
        return this.id.split('@')[0];
    }

    getRoomScope(){
        return this.id.split('@')[1];
    }

    createNewId(){
        return this.id =  this.subscribe +'@'+ new Date().getTime() +'@'+ (Math.random() * 0x1000000 << 0).toString(16) +'@'+ this.from;
    }

    check(socket){
        return true;
    }

    filter(msg){
        return true;
    }
    //解析房间id
    parseRoomId(str){
        return str.split('@')[0];
    }
    //解析房间scope
    parseRoomScope(str){
        return str.split('@')[0];
    }
}